home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / stevi69s.zip / HELP.C < prev    next >
Text File  |  1990-04-23  |  15KB  |  545 lines

  1. /* $Header: /nw/tony/src/stevie/src/RCS/help.c,v 1.9 89/08/06 09:50:09 tony Exp $
  2.  *
  3.  * Routine to display a command summary.
  4.  * (Dave Tutelman note:
  5.  *    I added the ability to page backwards and forwards through help.
  6.  *    In order to minimize the abuse to the existing code, I used
  7.  *    "goto"s and labeled each screen.  It's not the way I would have
  8.  *    done help from scratch, but it's not TOO ugly.
  9.  * )
  10.  * v1.1 Toad Hall Tweak, 20 Apr 90
  11.  */
  12.  
  13. #include <ctype.h>
  14. #include "stevie.h"
  15. #include "ascii.h"
  16. #include "keymap.h"
  17.  
  18. /* Macro to show help screen 'n'.
  19.  * If C supported label types, it'd be cleaner to do it that way. */
  20. #define    SHOWHELP( n )    switch(n) {        \
  21.             case 0: goto Screen0;   \
  22.             case 1: goto Screen1;    \
  23.             case 2: goto Screen2;    \
  24.             case 3: goto Screen3;    \
  25.             case 4: goto Screen4;    \
  26.             case 5: goto Screen5;    \
  27.             case 6: goto Screen6;    \
  28.             case 7: goto Screen7;    \
  29.             case 8: goto Screen8;   \
  30.             default: return (TRUE);    }
  31.  
  32. extern    char    *Version;
  33.  
  34. static    int    helprow;
  35. static    int    lastscreen = 0;        /* return to help in previous screen */
  36.  
  37. #ifdef    HELP
  38.  
  39. #ifdef __TURBOC__        /* v1.1 some local prototypes */
  40. void hparm (int p);
  41. #endif
  42.  
  43. static    void    longline();
  44.  
  45. bool_t
  46. help()
  47. {
  48. /*    int k; v1.1 never used */
  49.  
  50.     SHOWHELP( lastscreen );        /* where did we quit help last ? */
  51.  
  52. /***********************************************************************
  53.  * Zeroth Screen : Index to the help screens.
  54.  ***********************************************************************/
  55.  
  56. Screen0:
  57.     CLS;
  58.     windgoto(helprow = 0, 0);
  59.  
  60. longline("\
  61.    Index to HELP Screens\n\
  62.    =====================\n\n");
  63. longline("\
  64.       0    Help index  (this screen)\n\
  65.       1    Positioning within file, adjusting the screen\n\
  66.       2    Character positioning\n\
  67.       3    Line positioning, marking & returning, undo & redo\n");
  68. longline("\
  69.       4    Insert & replace, words, sentences, paragraphs\n\
  70.       5    Operators, miscellaneous operations, yank & put\n\
  71.       6    \"Ex\" command line operations\n\
  72.       7    Set parameters\n\
  73.       8    System-specific features\n");
  74.  
  75.     windgoto(0, 52);
  76.     longline(Version);
  77.  
  78.     SHOWHELP( helpkey (0) );
  79.  
  80.  
  81. /***********************************************************************
  82.  * First Screen:   Positioning within file, Adjusting the Screen
  83.  ***********************************************************************/
  84.  
  85. Screen1:
  86.     CLS;
  87.     windgoto(helprow = 0, 0);
  88.  
  89. longline("\
  90.    Positioning within file\n\
  91.    =======================\n\
  92.       ^F             Forward screenfull\n\
  93.       ^B             Backward screenfull\n");
  94. longline("\
  95.       ^D             scroll down half screen\n\
  96.       ^U             scroll up half screen\n");
  97. longline("\
  98.       G              Goto line (end default)\n\
  99.       ]]             next function\n\
  100.       [[             previous function\n\
  101.       /re            next occurence of regular expression 're'\n");
  102. longline("\
  103.       ?re            prior occurence of regular expression 're'\n\
  104.       n              repeat last / or ?\n\
  105.       N              reverse last / or ?\n\
  106.       %              find matching (, ), {, }, [, or ]\n");
  107. longline("\
  108. \n\
  109.    Adjusting the screen\n\
  110.    ====================\n\
  111.       ^L             Redraw the screen\n\
  112.       ^E             scroll window down 1 line\n\
  113.       ^Y             scroll window up 1 line\n");
  114. longline("\
  115.       z<RETURN>      redraw, current line at top\n\
  116.       z-             ... at bottom\n\
  117.       z.             ... at center\n");
  118.  
  119.     SHOWHELP( helpkey (1) );
  120.  
  121.  
  122. /***********************************************************************
  123.  * Second Screen:   Character positioning
  124.  ***********************************************************************/
  125.  
  126. Screen2:
  127.     CLS;
  128.     windgoto(helprow = 0, 0);
  129.  
  130. longline("\
  131.    Character Positioning\n\
  132.    =====================\n\
  133.       ^              first non-white\n\
  134.       0              beginning of line\n\
  135.       $              end of line\n\
  136.       h              backward\n");
  137. longline("\
  138.       l              forward\n\
  139.       ^H             same as h\n\
  140.       space          same as l\n\
  141.       fx             find 'x' forward\n");
  142. longline("\
  143.       Fx             find 'x' backward\n\
  144.       tx             upto 'x' forward\n\
  145.       Tx             upto 'x' backward\n\
  146.       ;              Repeat last f, F, t, or T\n");
  147. longline("\
  148.       ,              inverse of ;\n\
  149.       |              to specified column\n\
  150.       %              find matching (, ), {, }, [, or ]\n");
  151.  
  152.     SHOWHELP( helpkey (2) );
  153.  
  154.  
  155. /***********************************************************************
  156.  * Third Screen:   Line Positioning, Marking and Returning
  157.  ***********************************************************************/
  158.  
  159. Screen3:
  160.     CLS;
  161.     windgoto(helprow = 0, 0);
  162.  
  163. longline("\
  164.     Line Positioning\n\
  165.     ================\n\
  166.     H           home window line\n\
  167.     L           last window line\n\
  168.     M           middle window line\n");
  169. longline("\
  170.     +           next line, at first non-white\n\
  171.     -           previous line, at first non-white\n\
  172.     CR          return, same as +\n\
  173.     j           next line, same column\n\
  174.     k           previous line, same column\n");
  175.  
  176. longline("\
  177. \n\
  178.     Marking and Returning\n\
  179.     =====================\n\
  180.     ``          previous context\n\
  181.     ''          ... at first non-white in line\n");
  182. longline("\
  183.     mx          mark position with letter 'x'\n\
  184.     `x          to mark 'x'\n\
  185.     'x          ... at first non-white in line\n");
  186.  
  187. longline("\n\
  188.     Undo  &  Redo\n\
  189.     =============\n\
  190.     u           undo last change\n\
  191.     U           restore current line\n\
  192.     .           repeat last change\n");
  193.  
  194.     SHOWHELP( helpkey (3) );
  195.  
  196.  
  197. /***********************************************************************
  198.  * Fourth Screen:   Insert & Replace,
  199.  ***********************************************************************/
  200.  
  201. Screen4:
  202.     CLS;
  203.     windgoto(helprow = 0, 0);
  204.  
  205. longline("\
  206.     Insert and Replace\n\
  207.     ==================\n\
  208.     a           append after cursor\n\
  209.     i           insert before cursor\n\
  210.     A           append at end of line\n\
  211.     I           insert before first non-blank\n");
  212. longline("\
  213.     o           open line below\n\
  214.     O           open line above\n\
  215.     rx          replace single char with 'x'\n\
  216.     R           replace characters\n");
  217. if (! P(P_TO))
  218. longline("\
  219.     ~           change case (upper/lower) of single char\n");
  220.  
  221. longline("\
  222. \n\
  223.     Words, sentences, paragraphs\n\
  224.     ============================\n\
  225.     w           word forward\n\
  226.     b           back word\n\
  227.     e           end of word\n\
  228.     )           to next sentence\n\
  229.     }           to next paragraph\n");
  230. longline("\
  231.     (           back sentence\n\
  232.     {           back paragraph\n\
  233.     W           blank delimited word\n\
  234.     B           back W\n\
  235.     E           to end of W\n");
  236.  
  237.     SHOWHELP( helpkey (4) );
  238.  
  239.  
  240. /***********************************************************************
  241.  * Fifth Screen:   Operators, Misc. operations, Yank & Put
  242.  ***********************************************************************/
  243.  
  244. Screen5:
  245.     CLS;
  246.     windgoto(helprow = 0, 0);
  247.  
  248. longline("\
  249.     Operators (double to affect lines)\n\
  250.     ==================================\n\
  251.     d           delete\n\
  252.     c           change\n");
  253. longline("\
  254.     <           left shift\n\
  255.     >           right shift\n\
  256.     y           yank to buffer\n\
  257.     !           filter lines (command name follows)\n");
  258. if (P(P_TO))
  259. longline("\
  260.     ~           reverse case (upper/lower)\n");
  261.  
  262. longline("\n\
  263.     Miscellaneous operations\n\
  264.     ========================\n\
  265.     C           change rest of line\n\
  266.     D           delete rest of line\n\
  267.     s           substitute chars\n");
  268. longline("\
  269.     S           substitute lines (not yet)\n\
  270.     J           join lines\n\
  271.     x           delete characters\n\
  272.     X           ... before cursor\n");
  273.  
  274. longline("\n\
  275.     Yank and Put\n\
  276.     ============\n\
  277.     p           put back text\n\
  278.     P           put before\n\
  279.     Y           yank lines");
  280.  
  281.     SHOWHELP( helpkey (5) );
  282.  
  283.  
  284. /***********************************************************************
  285.  * Sixth Screen:   Command-line operations
  286.  ***********************************************************************/
  287.  
  288. Screen6:
  289.     CLS;
  290.     windgoto(helprow = 0, 0);
  291.  
  292. longline("\
  293.     EX command-line operations\n\
  294.     ==========================\n");
  295. longline("\
  296.     :w          write back changes\n\
  297.     :wq         write and quit\n\
  298.     :x          write if modified, and quit\n\
  299.     :q          quit\n\
  300.     :q!         quit, discard changes\n\
  301.     :e name     edit file 'name'\n\
  302.     :e!         reedit, discard changes\n");
  303. if (P(P_TG))
  304. longline("\
  305.     :e #        edit alternate file\n");
  306. else
  307. longline("\
  308.     :e #        edit alternate file (also ctrl-^)\n");
  309. longline("\
  310.     :w name     write file 'name'\n\
  311.     :n          edit next file in arglist\n\
  312.     :N          edit prior file in arglist\n\
  313.     :rew        rewind arglist\n\
  314.     :f          show current file and lines\n");
  315. longline("\
  316.     :f file     change current file name\n\
  317.     :g/pat/p|d  global command (print or delete only)\n\
  318.     :s/p1/p2/   text substitution (trailing 'g' optional)\n\
  319.     :ta tag     to tag file entry 'tag'\n\
  320.     ^]          :ta, current word is tag\n");
  321. if (P(P_TG))
  322. longline("\
  323.     :untag      back to before last ':ta' (also ctrl-^)\n");
  324. longline("\
  325.     :sh         run an interactive shell\n\
  326.     :!cmd       execute a shell command\n\
  327. ");
  328.  
  329.     SHOWHELP( helpkey (6) );
  330.  
  331.  
  332. /***********************************************************************
  333.  * Seventh Screen:   Set parameters
  334.  ***********************************************************************/
  335.  
  336. Screen7:
  337.     CLS;
  338.     windgoto(helprow = 0, 0);
  339.  
  340. longline("\
  341.     Set Parameters\n\
  342.     ==============\n");
  343. longline("\
  344.     :set param-name[=param-value]   to set\n\
  345.     :set sm, :set nosm, :set co=23  examples\n\
  346.     :set all    display all values\n\
  347.     :set        display non-default values\n\n");
  348. longline("Abbrev, name, and current value:\n");
  349. hparm(P_AI); hparm(P_SM); longline("\n");
  350. hparm(P_BK); hparm(P_CO); longline("\n");
  351. hparm(P_TS); hparm(P_MO); longline("\n");
  352. hparm(P_IC); hparm(P_ML); longline("\n");
  353. hparm(P_TG); hparm(P_TO); longline("\n");
  354. hparm(P_EB); hparm(P_VB); longline("\n");
  355. hparm(P_LI); hparm(P_NU); longline("\n");
  356. hparm(P_SS); longline(" (# of lines for ^D, ^U)\n");
  357. hparm(P_LS); longline(" (show tabs, newlines graphically)\n");
  358. hparm(P_RP); longline(" (min # of lines to report on oper)\n");
  359. hparm(P_WS); longline(" (search wraps around end of file)\n");
  360. hparm(P_CR); longline(" (write newline to file as CR-LF)\n");
  361.  
  362.     SHOWHELP( helpkey (7) );
  363.  
  364.  
  365. /***********************************************************************
  366.  * Eighth Screen:   System-Specific Features for DOS and OS/2
  367.  ***********************************************************************/
  368.  
  369. Screen8:
  370.     CLS;
  371.     windgoto(helprow = 0, 0);
  372.  
  373. longline("\
  374.     MSDOS & OS/2 Special Keys\n\
  375.     =========================\n");
  376. longline("\
  377.     The cursor keypad does pretty much what you'd expect,\n");
  378. longline("\
  379.     as long as you're not in text entry mode:\n\
  380. \n\
  381.     Home, End, PgUp, PgDn, and the arrow keys navigate.\n\
  382.     Insert    enter text before cursor.\n\
  383.     Delete    delete character at the cursor.\n\n");
  384.  
  385. longline("\
  386.     Function Keys\n\
  387.     =============\n\
  388.     F1      Help\n\
  389.     F2      Next file (:n)             Shift-F2  discard changes (:n!)\n\
  390.     F3      Previous file (:N)         Shift-F3  discard changes (:N!)\n");
  391. longline("\
  392.     F4      Alternate file (:e #)      Shift-F4  discard changes (:e! #)\n\
  393.     F5      Rewind file list (:rew)    Shift-F5  discard changes (:rew!)\n\
  394.     F6      Next function (]])         Shift-F6  Prev. function ([[)\n\
  395.     F8      Global subst. (:1,$s/)\n\
  396.     F10     Save & quit (:x)           Shift-F10 discard changes (:q!)");
  397.  
  398.     SHOWHELP( helpkey (8) );
  399.  
  400. }
  401.  
  402.  
  403. /*    longline (p)
  404.  *    Put the string p into the buffer, expanding newlines.
  405.  */
  406. static void
  407. longline(p)
  408. char    *p;
  409. {
  410.     register char    *s;
  411.  
  412.     for ( s = p; *s ;s++ ) {
  413.         if ( *s == '\n' )
  414.             windgoto(++helprow, 0);
  415.         else
  416.             outchar(*s);
  417.     }
  418. }
  419.  
  420. /*    hparm (n)
  421.  *    Put the help info for param #n into the buffer.
  422.  */
  423. void hparm (p)
  424.   int p;
  425. {
  426.     char    buf[25];
  427.     char    *bp;
  428.  
  429.     sprintf(buf, "     %6s  %-10s  ",
  430.             params[p].shortname, params[p].fullname);
  431.     bp = buf + strlen (buf);
  432.     if (params[p].flags & P_NUM)    /* numeric param */
  433.         sprintf(bp, "%-3d", params[p].value);
  434.     else {                /* Boolean param */
  435.         if (params[p].value)
  436.             strcpy (bp, "yes");
  437.         else
  438.             strcpy (bp, "no ");
  439.     }
  440.     longline (buf);
  441. }
  442.  
  443. /* Get keystroke and return instructions on what to do next.
  444.  * Argument is current help screen.
  445.  * Return value is target help screen, or -1 to quit help.
  446.  */
  447.  
  448. #ifdef DOS
  449. #  define    NSCREEN    8
  450. #else
  451. #ifdef OS2
  452. #  define    NSCREEN 8
  453. #else
  454. #  define    NSCREEN 7
  455. #endif
  456. #endif
  457.  
  458. int
  459. helpkey (n)
  460.   int n;
  461. {
  462.     static int    c = '\0';
  463.     int    prevkey;
  464.     char    banner [16];
  465.  
  466.     /* Start with instructions on navigating Help */
  467.     strcpy (banner, "PAGE 0 OF HELP");
  468.     banner [5] = (char)n + '0';
  469.     windgoto(helprow = Rows-4, 63);
  470.     longline(banner);
  471.     windgoto(helprow = Rows-3, 63);
  472.     longline("^^^^^^^^^^^^^^");
  473.     windgoto(helprow = Rows-2, 54);
  474.     longline("<Press Esc to quit Help>");
  475.     windgoto(helprow = Rows-1, 44);
  476.     longline("<Other keys navigate Help screens>\n");
  477.  
  478.     /* Now get keystrokes till we get a valid one */
  479.     while (1) {
  480.         prevkey = c;
  481.         c = vgetc();
  482.         switch (c) {
  483.           /* cases for Next Screen */
  484.           case ' ':      case '\t':
  485.           case '\n':      case '\r':    case '+':
  486.           case K_DARROW:
  487.           case 'f':      case CTRL('F'):
  488.           case CTRL('D'): case CTRL('Y'):
  489.           case 'n':      case 'N':    case CTRL('N'):
  490.           case 'j':
  491.             if (n < NSCREEN)    return (n+1);
  492.             break;
  493.  
  494.           /* cases for Previous Screen */
  495.           case BS:      case '-':
  496.           case K_UARROW:
  497.           case 'b':      case CTRL('B'):
  498.           case CTRL('U'): case CTRL('E'):
  499.           case 'p':      case 'P':    case CTRL('P'):
  500.           case 'k':
  501.             if (n > 0) return (n-1);
  502.             break;
  503.  
  504.           /* cases for Quit Help */
  505.           case ESC:
  506.           case 'Q':
  507.           case 'q':
  508.           case 'X':
  509.           case 'x':
  510.             lastscreen = n;        /* remember where we quit */
  511.             return (-1);
  512.  
  513.           /* "G" is presumed to be a "vi-style" go-to-line,
  514.            * except that we interpret it as go-to-screen.
  515.            */
  516.           case 'G':
  517.             /* If previous key was a number,
  518.              * we're already there.  Otherwise, go to
  519.              * last screen.
  520.              */
  521.             if (prevkey<(int)'0' || prevkey>NSCREEN+(int)'0')
  522.                 return (NSCREEN);
  523.             break;
  524.  
  525.           /* Default is screen number or invalid code */
  526.           default:
  527.             if (c>=(int)'0' && c<=NSCREEN+(int)'0')
  528.                 return ( c - (int)'0' );
  529.             break;
  530.         }
  531.     }
  532.     return(0);        /* v1.1 bogus - NEVER REACHED */
  533. }
  534.  
  535.  
  536. #else
  537.  
  538. bool_t
  539. help()
  540. {
  541.     msg("Sorry, help not configured");
  542.     return FALSE;
  543. }
  544. #endif
  545.